#ifndef _MYIO_H_
#define _MYIO_H_

#include "OSHeaders.h"
#include "OSMutex.h"

#ifndef WIN32
	#define OutputDebugString(a)
#endif

class CIOStreamEndl
{
};

class CIOStream
{
public:
	CIOStream();
	virtual ~CIOStream();

public:
	CIOStream& operator <<(char a);
	CIOStream& operator <<(UInt8 a);
	CIOStream& operator <<(Int16 a);
	CIOStream& operator <<(UInt16 a);
	CIOStream& operator <<(Int32 a);
	CIOStream& operator <<(UInt32 a);
	CIOStream& operator <<(Int64 a);
	CIOStream& operator <<(UInt64 a);
	CIOStream& operator <<(Float32 a);
	CIOStream& operator <<(const char *pData);
	CIOStream& operator <<(CIOStream & data);
	//flush
	CIOStream& operator <<(CIOStreamEndl &a);
	/*
	 * Buffer is end with null-terminated.
	 * INPUT:
	 * OUTPUT:
	 * RETURN:
         */
	const char*	GetBuffer();

	/*
	 * flush data.
	 * INPUT:
	 * OUTPUT:
	 * RETURN:
         */
	virtual void	Flush();

protected:
	void	Reset();

protected:
	char *		m_pBuffer;
	UInt32		m_CurPos;

	OSMutex		m_Mutex;
};

class COutput : public CIOStream
{
public:
	COutput();
	~COutput();
	virtual void Flush();
};

class CDumpToFile : public CIOStream
{
public:
	CDumpToFile(const char *pFile, Bool isOverride = TRUE);
	~CDumpToFile();

	virtual void Flush();

protected:
	FILE *	m_pFile;
};

extern COutput Output;
extern CIOStreamEndl Endl;
#endif	//_MYIO_H_
